﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace devtm.AutoMapper
{

    public class BoxMapper : INotifyPropertyChanged, IDisposable
    {


        private Mapper item;

        public BoxMapper(Mapper item)
        {
            this.item = item;
            this.PropertyChanged += new PropertyChangedEventHandler(BoxMapper_PropertyChanged);

            ItemMaps = new ObservableCollection<BoxItemMap>();

            foreach (ItemMap  itemMap in item.ItemMaps)            
                ItemMaps.Add(new BoxItemMap(itemMap));
            
        }

        private static string[] properties = new string[] { "ItemMaps", "TypeDestination" };

        void BoxMapper_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {

            if (PropertyChanged != null)
                if (properties.Contains(e.PropertyName))
                    PropertyChanged(this, e);

        }


        public string TypeDestination 
        { 
            get 
            {
                return "Convert to " + item.MappingDestination.TypeElement.FullName;
            } 
        }


        public event PropertyChangedEventHandler PropertyChanged;


        public ObservableCollection<BoxItemMap> ItemMaps { get; set; } 


        #region Dispose

        public void Dispose(bool disposing)
        {
            if (disposing)
            {

            }
            this.PropertyChanged -= new PropertyChangedEventHandler(BoxMapper_PropertyChanged);
        }

        public void Dispose()
        {
            Dispose(true);
        }

        ~BoxMapper()
        {
            Dispose(false);
        }

        #endregion



    }
}
